<?php
namespace app\index\controller;
use think\Controller;
use think\Request;
use think\Db;
use app\index\model\Users;
use app\index\model\Suggests;
/*意见与反馈*/
class Suggest extends Common
{
  //产品问题
  public function productList(){
  	$uid=(int)input('uid');
  	  if(empty($uid)){
          return json(['state'=>'203','msg'=>'用户为空']);
        }
       $rs=Users::selOne($uid);
       if($rs){
         $result=Suggests::productSel();
         if($result){
             return json($this->array_nonull(['state'=>'200','msg'=>'查询成功','result'=>$result]));
         }else{
            return json(['state'=>'201','msg'=>'查询内容不存在']); 
         }
       }else{
         return json(['state'=>'202','msg'=>'用户已不存在']);
       }
  } 
   //其他问题接口
  public function  problemList(){
  	$uid=(int)input('uid');
  	  if(empty($uid)){
          return json(['state'=>'203','msg'=>'用户为空']);
        }
       $rs=Users::selOne($uid);
       if($rs){
         $result=Suggests::problemSel();
         if($result){
             return json($this->array_nonull(['state'=>'200','msg'=>'查询成功','result'=>$result]));
         }else{
            return json(['state'=>'201','msg'=>'查询内容不存在']); 
         }
       }else{
         return json(['state'=>'202','msg'=>'用户已不存在']);
       }
  } 
//意见与反馈
  public function  feedbackAdd(){
     	$uid=(int)input('uid');
     	$productId=input('productId');//产品问题 可以为多个
      $problemId=input('problemId');//其他问题id 可以是多个
     	$content=input('content');//问题内容
  	  if(empty($uid) || empty($productId) || empty($problemId) || empty($content)){
          return json(['state'=>'203','msg'=>'参数不足']);
        }
       $rs=Users::selOne($uid);
       if($rs){
         $res=Db::name('user_feedback')->where("uid=$uid")->find();
         if(!empty($res)){
          return json(['state'=>'203','msg'=>'等待上个意见反馈审核']);
         }
        $data=['uid'=>$uid,'problemId'=>$problemId,'productId'=>$productId,'content'=>$content];
         $result=Suggests::feedbackSet($data);
         if($result){
             return json($this->array_nonull(['state'=>'200','msg'=>'添加成功等待后台查看','result'=>$result]));
         }else{
            return json(['state'=>'201','msg'=>'添加失败再试试']); 
         }
       }else{
         return json(['state'=>'202','msg'=>'用户已不存在']);
       }
  }

}  